import Vue from 'vue';
import Router from 'vue-router';
import { Util, AuthGuard } from '@/utils';

Vue.use(Router);

const router = new Router({
    routes: [
                {
            path: '/common_index/:common_index?',
            name: 'common_index',
            beforeEnter: (to: any, from: any, next: any) => {
                const routerParamsName = 'common_index';
                const params: any = {};
                if (to.params && to.params[routerParamsName]) {
                    Object.assign(params, Util.formatMatrixParse(to.params[routerParamsName]));
                }
                const url: string = 'v7/appdata';
                const auth: Promise<any> = AuthGuard.getInstance().authGuard(url, params, router);
                auth.then(() => {
                    next();
                }).catch(() => {
                    next();
                });
            },
            meta: {  
                caption: '首页',
                viewType: 'APPINDEX',
                requireAuth: true,
            },
            component: () => import('@pages/common/index/index'),
            children: [
                {
                    path: 'common_applyrejectview/:common_applyrejectview?',
                    name: 'common_applyrejectview',
                    meta: {  
                        caption: 'apply.views.rejectview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/common/apply-reject-view/apply-reject-view'),
                },
                {
                    path: 'common_applyapply_wrs_wfeditview3/:common_applyapply_wrs_wfeditview3?',
                    name: 'common_applyapply_wrs_wfeditview3',
                    meta: {  
                        caption: 'apply.views.apply_wrs_wfeditview3.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/common/apply-apply-wrs-wfedit-view3/apply-apply-wrs-wfedit-view3'),
                },
                {
                    path: 'common_applyapply_wld_wfeditview3/:common_applyapply_wld_wfeditview3?',
                    name: 'common_applyapply_wld_wfeditview3',
                    meta: {  
                        caption: 'apply.views.apply_wld_wfeditview3.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/common/apply-apply-wld-wfedit-view3/apply-apply-wld-wfedit-view3'),
                },
                {
                    path: 'common_applyapply_wzz_wfeditview3/:common_applyapply_wzz_wfeditview3?',
                    name: 'common_applyapply_wzz_wfeditview3',
                    meta: {  
                        caption: 'apply.views.apply_wzz_wfeditview3.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/common/apply-apply-wzz-wfedit-view3/apply-apply-wzz-wfedit-view3'),
                },
                {
                    path: 'common_applyapply_wrs_wfgridview/:common_applyapply_wrs_wfgridview?',
                    name: 'common_applyapply_wrs_wfgridview',
                    meta: {  
                        caption: 'apply.views.apply_wrs_wfgridview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/common/apply-apply-wrs-wfgrid-view/apply-apply-wrs-wfgrid-view'),
                },
                {
                    path: 'common_applygridview/:common_applygridview?',
                    name: 'common_applygridview',
                    meta: {  
                        caption: 'apply.views.gridview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/common/apply-grid-view/apply-grid-view'),
                },
                {
                    path: 'common_usergridview/:common_usergridview?',
                    name: 'common_usergridview',
                    meta: {  
                        caption: 'user.views.gridview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/common/user-grid-view/user-grid-view'),
                },
                {
                    path: 'common_applyapply_wld_wfgridview/:common_applyapply_wld_wfgridview?',
                    name: 'common_applyapply_wld_wfgridview',
                    meta: {  
                        caption: 'apply.views.apply_wld_wfgridview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/common/apply-apply-wld-wfgrid-view/apply-apply-wld-wfgrid-view'),
                },
                {
                    path: 'common_applyapply_wzz_wfgridview/:common_applyapply_wzz_wfgridview?',
                    name: 'common_applyapply_wzz_wfgridview',
                    meta: {  
                        caption: 'apply.views.apply_wzz_wfgridview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/common/apply-apply-wzz-wfgrid-view/apply-apply-wzz-wfgrid-view'),
                },
                {
                    path: 'common_usereditview/:common_usereditview?',
                    name: 'common_usereditview',
                    meta: {  
                        caption: 'user.views.editview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/common/user-edit-view/user-edit-view'),
                },
                {
                    path: 'common_applyeditview/:common_applyeditview?',
                    name: 'common_applyeditview',
                    meta: {  
                        caption: 'apply.views.editview.caption',
                        requireAuth: true,
                    },
                    component: () => import('@pages/common/apply-edit-view/apply-edit-view'),
                },
            ]
        },
        {
            path: '/login/:login?',
            name: 'login',
            meta: {  
                caption: '登录',
                viewType: 'login',
                requireAuth: false,
                ignoreAddPage: true,
            },
            beforeEnter: (to: any, from: any, next: any) => {
                router.app.$store.commit('resetRootStateData');
                next();
            },
            component: () => import('@components/login/login'),
        },
        {
            path: '/404',
            component: () => import('@components/404/404')
        },
        {
            path: '/500',
            component: () => import('@components/500/500')
        },
        {
            path: '*',
            redirect: 'common_index'
        }
    ],
});

export default router;
